package com.jeesite.modules.dp.web.kcgoumai;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.dp.entity.kcgoumai.DpKcgoumai;
import com.jeesite.modules.dp.service.kcgoumai.DpKcgoumaiService;

/**
 * 课程购买记录Controller
 * @author hancing.com
 * @version 2025-01-03
 */
@Controller
@RequestMapping(value = "${adminPath}/dp/kcgoumai/dpKcgoumai")
public class DpKcgoumaiController extends BaseController {

	@Autowired
	private DpKcgoumaiService dpKcgoumaiService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DpKcgoumai get(String id, boolean isNewRecord) {
		return dpKcgoumaiService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("dp:kcgoumai:dpKcgoumai:view")
	@RequestMapping(value = {"list", ""})
	public String list(DpKcgoumai dpKcgoumai, Model model) {
		model.addAttribute("dpKcgoumai", dpKcgoumai);
		return "modules/dp/kcgoumai/dpKcgoumaiList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("dp:kcgoumai:dpKcgoumai:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DpKcgoumai> listData(DpKcgoumai dpKcgoumai, HttpServletRequest request, HttpServletResponse response) {
		dpKcgoumai.setPage(new Page<>(request, response));
		Page<DpKcgoumai> page = dpKcgoumaiService.findPage(dpKcgoumai);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("dp:kcgoumai:dpKcgoumai:view")
	@RequestMapping(value = "form")
	public String form(DpKcgoumai dpKcgoumai, Model model) {
		model.addAttribute("dpKcgoumai", dpKcgoumai);
		return "modules/dp/kcgoumai/dpKcgoumaiForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("dp:kcgoumai:dpKcgoumai:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DpKcgoumai dpKcgoumai) {
		dpKcgoumaiService.save(dpKcgoumai);
		return renderResult(Global.TRUE, text("保存课程购买记录成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("dp:kcgoumai:dpKcgoumai:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DpKcgoumai dpKcgoumai) {
		dpKcgoumaiService.delete(dpKcgoumai);
		return renderResult(Global.TRUE, text("删除课程购买记录成功！"));
	}
	
}